﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ShopSpace.Core;

namespace ShopSpace.UI.DotNetNukeModules.Common
{
	public partial class ViewPersons : ModuleControlBase
	{
		protected void Page_Load(object sender, EventArgs e)
		{
			try
			{
				this.SetupLinks();
				if (!Page.IsPostBack)
				{
					this.BindPersons();
				}
			}
			catch (Exception ex)
			{
				this.HandleException(ex);
			}
		}

		protected void gvPersons_RowDataBound(object sender, GridViewRowEventArgs e)
		{
			if ( e.Row.RowType == DataControlRowType.DataRow )
			{
				Person person = (Person) e.Row.DataItem;

				Label lblUsername = (Label) e.Row.FindControl("lblUsername");
				lblUsername.Text = person.Username;

				Label lblDisplayName = (Label) e.Row.FindControl("lblDisplayName");
				lblDisplayName.Text = person.DisplayName;
			}
		}

		private void BindPersons()
		{
			this.gvPersons.DataSource = this.PersonRepository.ListByPortal(this.PortalId);
			this.gvPersons.DataBind();
		}

		private void SetupLinks()
		{
			this.hlAdd.NavigateUrl = EditUrl("EditPerson");
		}
	}
}